#include "StdAfx.h"
#include "ActionStack.h"

ActionStack::ActionStack(void)
{
	redoStack.clear();
	undoStack.clear();
}

ActionStack::~ActionStack(void)
{
}

void ActionStack::redo()
{
	if( !redoStack.empty() )
	{
		node* temp = redoStack.back();
		temp->action->redo();
		redoStack.pop_back();
		undoStack.push_back(temp);
	}
}

void ActionStack::undo()
{	
	if( !undoStack.empty() )
	{
		node *temp = undoStack.back();
		temp->action->undo();
		undoStack.pop_back();
		redoStack.push_back(temp);
	}
}

void ActionStack::push(Action* pAC,CUnit* unit)
{	
	if( !redoStack.empty() )
	{
		undoStack.clear();
		redoStack.clear();
	}
	node *temp = new node;
	temp->action = pAC;
	temp->unit = unit;
	undoStack.push_back(temp);
}
